package com.houhanzhi.controller;

import com.houhanzhi.response.JsonData;
import com.houhanzhi.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/product/v1")
public class ProductController {

    @Autowired
    private ProductService productService;


    /**
     * 商品列表
     * @return
     */
    @GetMapping("/list")
    public JsonData list() {
        return JsonData.buildSuccess(productService.list());
    }

    /**
     * 根据id查询商品详情
     * @param productId
     * @return
     */
    @GetMapping("/detail/{product_id}")
    public JsonData detail(@PathVariable("product_id") long productId) {
        return JsonData.buildSuccess(productService.findDetailById(productId));
    }
}
